import requests
from DataTest.JsonData.read_json import load_json
from DataTest.ANR.path import *

self_token = load_json(json_data_path)


def get_question():
    """
    获取问题id
    通过问题id回答对应问题
    :return:self_token 回答问题，match_token 不回答问题
    """
    get_question_url = 'http://124.220.33.63:8700/question/receive'
    answer_question_url = 'http://124.220.33.63:8700/question/answer'
    user_n = 1
    for token in self_token:
        header = {
            'Authorization': f'Bearer {token}',
            'Content-Type': 'application/json',
        }
        # 获取问题id
        question_res = requests.post(url=get_question_url, headers=header)
        question_id = question_res.json().get('data').get('ID')
        # 回答问题
        answer_data = {
            "ID": question_id,
            "Answer": f"这是第{user_n}个用户的回答，token：“{token}"
        }
        answer_res = requests.post(url=answer_question_url, headers=header, json=answer_data)
        # print(answer_res.json())
        if answer_res.json().get('code') != 200:
            print(f"用户{token}回答失败")
